package com.treasure.mall.zbqmallapi.vo.auction;

import com.treasure.mall.biz.entity.auction.AuctionBidPO;
import com.treasure.mall.biz.mapstruct.UserMapStruct;
import com.treasure.mall.biz.vo.BaseVO;
import com.treasure.mall.biz.vo.user.UserVO;
import com.treasure.mall.zbq.common.Jsr310Utils;
import com.treasure.mall.zbq.common.ienum.auction.AuctionEnums;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;

/**
 * @author allan
 * @version 1.0.0
 * @date 2020/7/17
 */
@Data
@NoArgsConstructor
public class AuctionBidVO implements BaseVO {
    private static final long serialVersionUID = 6296772262957477399L;

    private Long id;
    /**
     * 出价人
     */
    private UserVO userVO;
    /**
     * 出价金额
     */
    private BigDecimal bidAmount;
    private String createTime;
    private String productName;
    private Long productId;
    private String thumbnail;
    private boolean success;
    /**
     * 当前的最高价
     */
    private BigDecimal topPrice;
    /**
     * 对应的销售订单号
     */
    private String orderId;
    /**
     * 支付超时时间，可能为空
     */
    private String payExpireTime;
    /**
     * 竞拍结束时间
     */
    private String bidEndTime;

    private Long auctionSessionId;


    private AuctionEnums.AuctionStatus auctionStatus;

    public AuctionBidVO(AuctionBidPO po) {
        this.id = po.getId();
        this.userVO = UserMapStruct.INSTANCE.po2vo(po.getUserPO());
        this.bidAmount = po.getBidAmount();
        this.createTime = Jsr310Utils.DateTime.asString(po.getCreateTime());
        this.productName = po.getSessionPO().getProductPO().getProductName();
        this.productId = po.getSessionPO().getProductPO().getProductId();
        this.thumbnail = po.getSessionPO().getProductPO().getMainPic();
        this.success = po.isSuccess();
        this.orderId = po.getDealOrderId();
        this.payExpireTime = Jsr310Utils.DateTime.asString(po.getPayExpireTime());
        this.bidEndTime = Jsr310Utils.DateTime.asString(po.getSessionPO().getEndTime());
        if (po.getSessionPO().getWinner() == null) {
            this.topPrice = po.getSessionPO().getStartingPrice();
        } else {
            this.topPrice = po.getSessionPO().getWinner().getBidAmount();
        }

        this.auctionSessionId = po.getSessionPO().getId();
        this.auctionStatus = po.getSessionPO().getAuctionStatus();
    }
}
